﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace SharePoint.Contrib.Extensions
{
    /// <summary>
    /// Extension methods for the SPUser class
    /// </summary>
    public static class SPUserExtensions
    {
        /// <summary>
        /// Returns the account name (someuser) without the domainpart in ex: domain\\someuser
        /// </summary>
        public static string AccountNameWithoutDomain(this SPUser instance)
        {
            string account = instance.LoginName;

            if (string.IsNullOrEmpty(account))
            {
                return string.Empty;
            }
            if (account.IndexOf(@"\") > 0)
            {
                return account.Substring(account.IndexOf(@"\") + 1);
            }
            else
            {
                return account;
            }
        }

    }
}
